<template>
  <!--视图-->

  <div>
    <h1>农产品溯源登录</h1>
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-form-item label="用户名">
        <el-input v-model="formInline.userName" placeholder="用户名"></el-input>
      </el-form-item><br>
      <el-form-item label="密码">
        <el-input v-model="formInline.password" placeholder="密码" show-password></el-input>
      </el-form-item><br>
      <el-form-item label="验证码">
        <el-input v-model="formInline.code" placeholder="验证码"></el-input>
      </el-form-item> <br>
      <el-image :src="imgUrl" @click="getyzm"></el-image>
      <br>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "LoginView",
  data() {//属性
    return {
      imgUrl:"",
      formInline:{}
    }
  }, methods: {//自定义方法
    getyzm()
    {
      let uid=sessionStorage.getItem("uid");
      this.formInline.uuid=uid;
      console.log(uid)
      this.imgUrl="http://localhost:8090/user/getyzm?uuid="+uid+"&time="+new Date().getTime();

    },
    onSubmit()
    {
      this.axios.post("/auth/user/login",this.formInline).then(res=>{
        if(res.data.code==200)
        {
          this.$message.success(res.data.msg);
          sessionStorage.setItem("token",res.data.data);
          console.log(res.data.data)
          this.$router.push("/tree");
        }else
        {
          this.$message.error(res.data.msg);
        }

      })
    }
  }, created() { //钩子函数
      this.getyzm();
  }
}
</script>

<style scoped>

</style>